/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.ImageTypeManager;
import model.admin.ImageType;

/**
 *
 * @author TuanAnh
 */
@ManagedBean
@RequestScoped
public class ImageTypeBean {

    private int Image_Type_Id;
    private boolean Image_Type_Status;
    private String Image_Type_Name;

    /**
     * Creates a new instance of ImageTypeBean
     */
    public ImageTypeBean() {
    }

    public ImageTypeBean(int Image_Type_Id, boolean Image_Type_Status, String Image_Type_Name) {
        this.Image_Type_Id = Image_Type_Id;
        this.Image_Type_Status = Image_Type_Status;
        this.Image_Type_Name = Image_Type_Name;
    }

    public int getImage_Type_Id() {
        return Image_Type_Id;
    }

    public void setImage_Type_Id(int Image_Type_Id) {
        this.Image_Type_Id = Image_Type_Id;
    }

    public boolean isImage_Type_Status() {
        return Image_Type_Status;
    }

    public void setImage_Type_Status(boolean Image_Type_Status) {
        this.Image_Type_Status = Image_Type_Status;
    }

    public String getImage_Type_Name() {
        return Image_Type_Name;
    }

    public void setImage_Type_Name(String Image_Type_Name) {
        this.Image_Type_Name = Image_Type_Name;
    }

    public List<ImageType> loadData() {
        ImageTypeManager m = new ImageTypeManager();
        return m.getAll();
    }

    public String insert() {
        ImageType model = new ImageType(Image_Type_Id, Image_Type_Status, Image_Type_Name);
        ImageTypeManager mana = new ImageTypeManager();
        boolean flag = mana.insert(model);
        if (flag) {
            loadData();
            return "ImagerManager.xhtml";
        }
        return "";
    }

    public String EditImage(int id, String name, Boolean status) {
        this.Image_Type_Id = id;
        this.Image_Type_Name = name;
        this.Image_Type_Status = status;
        return "updateImageType.xhtml";
    }

    public void sua() {
        ImageTypeManager mana = new ImageTypeManager();
        ImageType m = new ImageType(Image_Type_Id, Image_Type_Status, Image_Type_Name);
        mana.update(m);
    }

    public void delete(int id) {
        ImageTypeManager mana = new ImageTypeManager();
        mana.delete(id);
        loadData();
    }

    public void reset() {
        this.Image_Type_Id = 0;
        this.Image_Type_Name = "";
        this.Image_Type_Status = false;
    }
}
